#!/bin/bash
set -o errexit  \
    -o nounset  \
    -o pipefail

# ${1} -> ENDPOINT
# ${2} -> HEAD
# ${3} -> TITLE

read -d '' -r DATA <<EOF || true
{
  "title": "${3}",
  "head":  "${2}",
  "base":  "master",
  "draft": true
}
EOF

curl                                                 \
  -X POST                                            \
  -H "Accept: application/vnd.github.v3+json"        \
  -H "Authorization: Bearer ${GITHUB_MACHINE_TOKEN}" \
  "${1}" -d "${DATA}"

